package net.pws.oos.biz.query.impl;

import java.util.List;
import java.util.Map;

import net.pws.common.persistence.QueryRepository;
import net.pws.oos.biz.model.Area;
import net.pws.oos.biz.query.AreaFinder;

import org.springframework.stereotype.Service;

@Service
@SuppressWarnings({ "unchecked", "rawtypes" })
public class DefaultAreaFinder extends AbstractFinder implements AreaFinder {
    
    @Override
    public List<Area> listProvinces() {
        String hql = QueryRepository.getInstance().get("hql.listProvice");
        return entityManager.findList(hql, new Object[0]);
    }
    
    @Override
    public List<Area> listCities(String provinceId) {
        String hql = QueryRepository.getInstance().get("hql.listCity");
        return entityManager.findList(hql, new Object[] { provinceId });
    }
    
    @Override
    public int countCities(String proviceId) {
        String hql = QueryRepository.getInstance().get("hql.countCity");
        Number count = (Number) entityManager.findFirst(hql,
                                                        new Object[] { proviceId });
        return count.intValue();
    }
    
    @Override
    public Map getArea(String id) {
        String hql = QueryRepository.getInstance().get("hql.getArea");
        return (Map) entityManager.findFirst(hql, new Object[] { id });
    }
    
}
